<?php
namespace App\Services;


use Framework\BaseService;
use Framework\Lockable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Ytake\LaravelAspect\Annotation\Cacheable;
use Tests\Models\User;

class TestService extends BaseService
{



    /**
     */
    public function cacheable(): array
    {
        return [123,4124];
    }

    /**
     * @Lockable(cacheName="binfa", key={"#name"})
     * @param string $name
     * @throws \Throwable
     */
    public function binfa(string $name)
    {
        $flg = OrderModel::query()->where('order_name', $name)->exists();
        if ($flg) {
            $this->retError('已存在');
        }

        sleep(5);

        $info = new OrderModel();
        $info->order_name = $name;
        $info->order_num = rand(1, 10);
        $info->saveOrFail();
    }
}
